// 基础类型定义
export interface BaseEntity {
  id: string | number;
  createdAt: string;
  updatedAt: string;
}

// API 响应类型
export interface ApiResponse<T = any> {
  code: number;
  message: string;
  data: T;
  success: boolean;
}

// 分页参数
export interface PaginationParams {
  page: number;
  pageSize: number;
  total?: number;
}

// 分页响应
export interface PaginatedResponse<T> {
  list: T[];
  pagination: {
    current: number;
    pageSize: number;
    total: number;
  };
}

// 用户相关类型
export interface User extends BaseEntity {
  username: string;
  email: string;
  phone?: string;
  avatar?: string;
  status: 'active' | 'inactive';
  role: string;
  lastLoginAt?: string;
  profile?: UserProfile;
}

export interface UserProfile {
  firstName?: string;
  lastName?: string;
  gender?: 'male' | 'female' | 'other';
  birthday?: string;
  address?: string;
  bio?: string;
}

// 角色权限类型
export interface Role extends BaseEntity {
  name: string;
  code: string;
  description?: string;
  permissions: Permission[];
  status: 'active' | 'inactive';
}

export interface Permission extends BaseEntity {
  name: string;
  code: string;
  resource: string;
  action: string;
  description?: string;
}

// 菜单类型
export interface MenuItem {
  key: string;
  label: string;
  icon?: React.ReactNode;
  path?: string;
  children?: MenuItem[];
  permission?: string;
  hidden?: boolean;
}

// 表格列配置
export interface TableColumn {
  title: string;
  dataIndex: string;
  key: string;
  width?: number;
  fixed?: 'left' | 'right';
  sorter?: boolean;
  filters?: Array<{ text: string; value: any }>;
  render?: (value: any, record: any, index: number) => React.ReactNode;
}

// 表单字段类型
export interface FormField {
  name: string;
  label: string;
  type: 'input' | 'textarea' | 'select' | 'date' | 'upload' | 'switch' | 'radio' | 'checkbox';
  required?: boolean;
  placeholder?: string;
  options?: Array<{ label: string; value: any }>;
  rules?: any[];
  props?: any;
}

// 文件上传类型
export interface UploadFile {
  uid: string;
  name: string;
  status: 'uploading' | 'done' | 'error' | 'removed';
  url?: string;
  thumbUrl?: string;
  size?: number;
  type?: string;
}

// 通知类型
export interface Notification extends BaseEntity {
  title: string;
  content: string;
  type: 'info' | 'success' | 'warning' | 'error';
  read: boolean;
  userId: string;
}

// 系统设置类型
export interface SystemConfig {
  siteName: string;
  siteDescription: string;
  logo?: string;
  favicon?: string;
  theme: 'light' | 'dark';
  language: string;
  timezone: string;
  emailConfig?: EmailConfig;
  smsConfig?: SmsConfig;
}

export interface EmailConfig {
  host: string;
  port: number;
  username: string;
  password: string;
  secure: boolean;
  from: string;
}

export interface SmsConfig {
  provider: string;
  accessKey: string;
  secretKey: string;
  signName: string;
}

// 数据统计类型
export interface Statistics {
  totalUsers: number;
  totalOrders: number;
  totalRevenue: number;
  totalViews: number;
  userGrowth: number;
  orderGrowth: number;
  revenueGrowth: number;
  viewGrowth: number;
}

// 图表数据类型
export interface ChartData {
  name: string;
  value: number;
  date?: string;
}

// 订单类型
export interface Order extends BaseEntity {
  orderNo: string;
  userId: string;
  userName: string;
  amount: number;
  status: 'pending' | 'processing' | 'completed' | 'cancelled';
  items: OrderItem[];
  shippingAddress?: Address;
  paymentMethod?: string;
  paidAt?: string;
  shippedAt?: string;
  deliveredAt?: string;
}

export interface OrderItem {
  id: string;
  productId: string;
  productName: string;
  price: number;
  quantity: number;
  total: number;
}

export interface Address {
  province: string;
  city: string;
  district: string;
  street: string;
  zipCode?: string;
  contact: string;
  phone: string;
}

// 产品类型
export interface Product extends BaseEntity {
  name: string;
  description?: string;
  price: number;
  originalPrice?: number;
  stock: number;
  images: string[];
  categoryId: string;
  categoryName: string;
  status: 'active' | 'inactive';
  tags?: string[];
  attributes?: ProductAttribute[];
}

export interface ProductAttribute {
  name: string;
  value: string;
}

// 分类类型
export interface Category extends BaseEntity {
  name: string;
  description?: string;
  parentId?: string;
  level: number;
  sort: number;
  status: 'active' | 'inactive';
  children?: Category[];
}

// 日志类型
export interface SystemLog extends BaseEntity {
  level: 'info' | 'warn' | 'error' | 'debug';
  message: string;
  module: string;
  userId?: string;
  userName?: string;
  ip?: string;
  userAgent?: string;
  extra?: any;
}
